// pages/dispatch/tongji/index.js

import {
  craet_zhandians,
  collectionInfo
} from '../../../utils/api/index.js';



var data = [
  { name: '已揽收', value: 30, color: '#07b248' },
  { name: '已取票', value: 70, color: '#76eca2' } 
]
const liuxiang_data = 
  [{
    name: '省内',
    data: [21, 32, 46, 66, 12 ],
    color: 'rgba(7,179,72,1.000000)',
  },
  {
    name: '省外',
    data: [11, 12, 26, 26, 2],
    color: 'rgba(253,140,53,1.000000)',
  } 
  ];
  const xLabel = ['上海', '北京', '沈阳', '南京', '杭州'];
const options2 = {
  data: liuxiang_data,
  xLabel: xLabel,
  style: 'line',
  lineStyle: 'curve',
  xWordsCnt: 4,
  xRows: 1,
  area: false,
  showTooltip: true,
  tooltip: '{a}：{b}',
  showLabel: false,
  nowdate:'2024-03-05',
  date: '2024-03-05',//默认起始时间  
  date2: '2024-03-05',//默认结束时间 
};

const liuxiang_data2 = 
  [{
    name: '省内',
    data: [61, 32, 46, 66, 82 ],
    color: 'rgba(7,179,72,1.000000)',
  },
  {
    name: '省外',
    data: [41, 12, 26, 26, 72],
    color: 'rgba(253,140,53,1.000000)',
  } 
  ];
  const xLabel2 = ['广州', '北京', '沈阳', '南京', '杭州'];
const options3 = {
  data: liuxiang_data2,
  xLabel: xLabel2,
  style: 'line',
  lineStyle: 'curve',
  xWordsCnt: 4,
  xRows: 1,
  area: false,
  showTooltip: true,
  tooltip: '{a}：{b}',
  showLabel: false,
};
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    companyArray:['公司1','公司2'],
    selCompany:{
      companyName: '切分公司'
    },
    selete2Arr: ['苹果','香蕉','草莓','榴莲'],
    selete2Name: '切果品',

    // 表格
    dpr: wx.getSystemInfoSync().windowWidth,
    lineChart:'',
    lineChart2:'',
    paihangChange:'PRINTED',
    swdata:[  {
      zhandian:"果满园",
      liuxiang:"2,233",
      ziti:"2,233",
      zaipei:"3",
      wuliu:"圆通速递"
    },
    {
      zhandian:"果满园",
      liuxiang:"2,233",
      ziti:"2,233",
      zaipei:"3",
      wuliu:"圆通速递"
    },{
      zhandian:"果满园",
      liuxiang:"2,233",
      ziti:"2,233",
      zaipei:"3",
      wuliu:"圆通速递"
    },
    {
      zhandian:"果满园",
      liuxiang:"2,233",
      ziti:"2,233",
      zaipei:"3",
      wuliu:"圆通速递"
    },{
      zhandian:"果满园",
      liuxiang:"2,233",
      ziti:"2,233",
      zaipei:"3",
      wuliu:"圆通速递"
    },
    {
      zhandian:"果满园",
      liuxiang:"2,233",
      ziti:"2,233",
      zaipei:"3",
      wuliu:"圆通速递"
    },{
      zhandian:"果满园",
      liuxiang:"2,233",
      ziti:"2,233",
      zaipei:"3",
      wuliu:"圆通速递"
    }],
    idx:0,
    tabactive:'all',
    active: 'tongji',
    date: '2024-03-05',//默认起始时间  
    date2: '2024-03-05',//默认结束时间 
     //分页数据
     pageNumber:1,
     pagetotal:5,
     page:1
  },
   // 切换公司
   changeCompany(e) {
    console.log(e)
    let index = e.detail.value
    this.setData({
      fruitId: undefined,
      selCompany:{
        companyName: this.data.companyArray[index]
      },
    })
    // // 切换公司时清空页面数据
    // this.clearPageData()
    // app.globalData.fruit = null;

    // console.log("清除");
    // // 清空上次默认选择水果
    // wx.removeStorageSync('selectFruit')

    // // 记录选择分公司
    // wx.setStorageSync('selectCompany', {
    //   companyId: this.data.selCompany.companyId,
    // });
    // // 获取水果列表
    // this.getFruitList()
  },
  changeCompany2(e) {
    console.log(e)
    let index = e.detail.value
    this.setData({
      selete2Name: this.data.selete2Arr[index]
    })
  },
  onChange(event) {
    this.setData({ active: event.detail });
    switch ( event.detail){
      case 'tongji':
        wx.redirectTo({ 
          url: '/pages/dispatch/tongji/index'
        });
        break;
        case 'order':
          wx.redirectTo({ 
            url: '/pages/dispatch/order/index'
          });
          break;
          case 'dispatch':
            wx.redirectTo({ 
              url: '/pages/dispatch/dispatchManage/index/index'
            });
            break;
            case 'receive':
              wx.redirectTo({ 
                url: '/pages/dispatch/receive/index/index'
              });
              break;
              case 'mine':
                wx.redirectTo({ 
                  url: '/pages/dispatch/mine/index/index'
                });
                break;
    } 
  },
  //上一页
  prevFn:function(){
    if(this.data.pageNumber <=1){
      wx.showToast({
        icon:'none',
        title: '已经是最前一页',
      })
      return;
    }
    
    wx.showLoading({
      title: '加载中...',
    })
    this.setData({
      pageNumber:Number(this.data.pageNumber)-1
    })
    console.log(this.data.pageNumber);
    setTimeout(function(){
      wx.hideLoading()
    },1000)
  },
  //下一页
  nextFn:function(){
    if(this.data.pageNumber === this.data.pagetotal){
      wx.showToast({
        icon:'none',
        title: '已经是最后一页',
      })
      return;
    }
    wx.showLoading({
      title: '加载中...',
    })
    this.setData({
      pageNumber:Number(this.data.pageNumber)+1
    })
    console.log(this.data.pageNumber);
    setTimeout(function(){
      wx.hideLoading()
    },1000)
  },
 
  paihangChange(e) { 
    console.log(e)
    this.setData({
      paihangChange: e.target.dataset.self,
    })
  },
  changeAll(e) { 
    console.log(e)
    this.setData({
      tabactive: e.target.dataset.self,
    })
  },
  // 时间段选择  
  bindDateChange(e) {
    let that = this;
    console.log(e.detail.value)
    that.setData({
      date: e.detail.value,
    }) 
  },
  bindDateChange2(e) {
    let that = this;
    that.setData({
      date2: e.detail.value,
    }) 
  },
   //cs
   getMyCoupon() {
    
    collectionInfo({  
    }).then(res => {

      console.log("这是查询调度请求返回",res)
        if (res.resultStatus) {
          if (res.resultData !== null) {
            let coupon = res.resultData.map((v) => { 
              console.log("这是请求配置后",v)
              return v;
            })
            
          }
        }
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
//this.getMyCoupon() 
    const date = new Date()
    const year = date.getFullYear()
    const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1
    const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()
    this.setData({
      date: `${year}-${month}-${day}`,
      date2: `${year}-${month}-${day}`
    }) 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {  
    this.lineChart = this.selectComponent('#line');
    this.lineChart.setOptions(options2);
    this.lineChart.initChart(350, 233); 


    this.lineChart2 = this.selectComponent('#line2');
    this.lineChart2.setOptions(options3);
    this.lineChart2.initChart(350, 233); 


    var options = {
      data: data,
      legend: '{c}',
      chartRatio: 0,
      style: 'ring',
      showLegend: false,
      showLabel: false,
      animation: true,
      showTooltip: true,
      tooltip: '{a}：{b}人',
    }
    this.roseComp = this.selectComponent('#ring');
    this.roseComp.setOptions(options);
    this.roseComp.initChart(120, 120);




  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})